import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: {title: '首页', icon: 'dashboard',affix: true,noCache: true,},

    }]
  },
  {
    path: '/indent',
    component: Layout,
    children: [{
      path: 'index',
      name: 'indent',
      component: () => import('@/views/indent/index'),
      meta: {title: '订单管理', icon: 'form'}
    }]
  }, {
    path: '/dispatch',
    component: Layout,
    children: [{
      path: 'index',
      name: 'dispatch',
      component: () => import('@/views/dispatch/index'),
      meta: {title: '调度管理', icon: 'engineer'}
    }]
  }, 
  {
    path: '/finance',
    component: Layout,
    children: [{
      path: 'index',
      name: 'finance',
      component: () => import('@/views/finance/index'),
      meta: {title: '财务管理', icon: 'work'}
    }]
  },{
    path: '/allocation',
    component: Layout,
    redirect: '/allocation/index',
    alwaysShow: true,
    name: 'allocation',
    meta: {title: '配置管理', icon: 'equipment'},
    children: [{
      path: 'index',
      name: 'allocation',
      component: () => import('@/views/allocation/index'),
      meta: {title: '接驳类型'}
    }, {
      path: 'indentType',
      name: 'indent_type',
      component: () => import('@/views/allocation/indent_type'),
      meta: {title: '订单类型'},
    }, {
      path: 'service',
      name: 'service',
      component: () => import('@/views/allocation/service'),
      meta: {title: '服务类型'},
    }, {
      path: 'byBus',
      name: 'byBus',
      component: () => import('@/views/allocation/byBus'),
      meta: {title: '坐车类型'},
    }, {
      path: 'price',
      name: 'price',
      component: () => import('@/views/allocation/price'),
      meta: {title: '价格设置'},
    }]
  }, {
    path: '/personal',
    component: Layout,
    redirect: '/personal/index',
    alwaysShow: true,
    name: 'personal',
    meta: {title: '用户管理', icon: 'equipment_type'},
    children: [{
      path: 'index',
      name:"personal",
      component: () => import('@/views/personal/index'),
      meta: {title: '旅行社管理'}
    },{
      path: 'travel',
      name:"travel",
      component: () => import('@/views/personal/travel'),
      meta: {title: '旅行社人员管理'}
    },{
      path: 'car',
      name:"car",
      component: () => import('@/views/personal/car'),
      meta: {title: '车辆公司管理'}
    },{
      path: 'carManage',
      name:"carManage",
      component: () => import('@/views/personal/carManage'),
      meta: {title: '车辆公司管理员'}
    },{
      path: 'drive',
      name:"drive",
      component: () => import('@/views/personal/drive'),
      meta: {title: '司机管理员'}
    }]
  },
  // 404 page must be placed at the end !!!
  {path: '*', redirect: '/404', hidden: true}
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({y: 0}),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
